package com.zzyl.nursing.controller.member;

import com.zzyl.common.constant.HttpStatus;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationPageDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.ReservationCountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;


    /**
     * 查询取消预约数量
     * @return Integer
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {

        Integer count =  reservationService.getCancelledReservationCount();
       
        return R.ok(count);
    }


    /**
     * 小程序新增预约参观
     * @return
     */
    @PostMapping
    public AjaxResult insertReservationByTime(@RequestBody Reservation reservation) {

        reservationService.insertReservation(reservation);
        return success();

    }


    /**
     * 预约分页查询
     * @param reservationPageDto
     * @return R<TableDataInfo<Reservation>>
     */
    @GetMapping("/page")
    public R<TableDataInfo<Reservation>> findReservationByPage(ReservationPageDto reservationPageDto) {

        TableDataInfo<Reservation> reservationTableDataInfo = reservationService.findReservationByPage(reservationPageDto);

        return R.ok(reservationTableDataInfo);
    }


    /**
     * 小程序取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    public AjaxResult cancelReservation(@PathVariable Long id) {


        reservationService.cancelReservation(id);

        return success();

    }

    /**
     * 分时间段统计预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public R<List<ReservationCountByTimeVo>> countByTime(Long time){

        List<ReservationCountByTimeVo> list = reservationService.countByTime(time);
        return R.ok(list);
    }






}